﻿/*----------------------------------------------------------------
    // Copyright (C) 2009 江苏华招网
    // 版权所有。 
    // 作者：周传雄 
    //
    // 文件名：DistributePlanList.cs
    // 文件功能描述：发票明细
    // 创建标识：周传雄2009-05-12
    //
    // 修改标识：
    // 修改描述：
    //
    // 修改标识：
    // 修改描述：
    //
    // 审核人：
// 审核时间：
// 审核说明：
 //----------------------------------------------------------------*/
using System;
using System.Collections;
using System.Configuration;
using System.Data;

using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using HZ.DrugTrade.Model;
using HZ.DrugTrade.IBLL;
using HZ.DrugTrade.BLLFactory;
using HZ.DrugTrade.Model.Enum;
using System.Collections.Generic;
using HZ.DrugTrade.Web;
using HZ.Common;


namespace HZ.DrugTrade.Web.Enterprise.InvoiceManage
{
    public partial class RefundDetailInvoice : BasePage
    {
        public RefundDetailInvoice()
        {
            this.ModuleNo = Module.结算单管理.ToString();
        }

        public string str_InvoiceID = "";
        protected void Page_Load(object sender, EventArgs e)
        {
            //获取发票ID
            if (Request.QueryString["isID"] != null)
            {
                str_InvoiceID = Request.QueryString["isID"].ToString();
            }
            else { return; }

            if (!Page.IsPostBack)
            {
                QueryResult();
                ShowInvocieInfo();
            }
        }
        /// <summary>
        /// 数据绑定,获取发票的详细信息
        /// </summary>
        private void QueryResult()
        {
            IList<Model.View.InvoiceDistribution> lstInvoicePay = new List<Model.View.InvoiceDistribution>();
            Model.Query.InvoiceDistribution qryCondition = new Model.Query.InvoiceDistribution();
            User user = CurrentAccount.GetUser();
            qryCondition.CompanyID_PS = user.Org.OrgID;
            qryCondition.InvoiceID = str_InvoiceID;
            qryCondition.OrderName = txtOrderName.Text.ToString().Trim();
            qryCondition.GoodsName = txtGoodsName.Text.ToString().Trim();
            qryCondition.Material = txtMaterial.Text.ToString().Trim();
            qryCondition.PinyinCode = this.txtpinyincode.Text.Trim().ToUpper();
            qryCondition.Outlookc = txtOutLookc.Text.ToString().Trim();
            //qryCondition.HospitalName = txtHospitalName.Text.ToString().Trim();
            qryCondition.DistributeTimeFrom = new HZ.Common.ConvertHelper(txtTimeFrom.Text.ToString().Trim()).ToDateTime;
            qryCondition.DistributeTimeTo = new HZ.Common.ConvertHelper(txtTimeTo.Text.ToString().Trim()).ToDateTime;
            qryCondition.SortFields = " InvoiceTime desc ";
            qryCondition.ProjectID = this.ddlProjectid.SelectedValue;
            //AspNetPager1.PageSize = Constants.GRIDVIEW_PAGE_SIZE;
            int totalCount = 0;
            IBLL_Purchase iPurchase = Factory.BLL_Purchase();
            lstInvoicePay = iPurchase.GetInvoiceDistributionByWhere(qryCondition, AspNetPager1.CurrentPageIndex, AspNetPager1.PageSize, out totalCount);
            AspNetPager1.RecordCount = totalCount;
            gvwRefundDetail.DataSource = lstInvoicePay;
            gvwRefundDetail.DataBind();

        }

        protected void btnQuery_Click(object sender, EventArgs e)
        {
            AspNetPager1.CurrentPageIndex = 1;     //update by lhl 2009-08-30
            QueryResult();
        }
        protected void AspNetPager1_OnPageChanged(object sender, EventArgs e)
        {
            QueryResult();
        }


        /// <summary>
        /// 显示发票信息
        /// </summary> 
        private void ShowInvocieInfo()                          //add by lhl 2009-08-30
        {
            IBLL_Purchase iPurchase = Factory.BLL_Purchase();
            Model.Query.Invoice qryCondition = new Model.Query.Invoice();
            qryCondition.InvoiceID = str_InvoiceID;
            int totalCount = 0;
            Model.View.Invoice invoice = iPurchase.GetInvoiceByWhere(qryCondition, 1, 0, out totalCount)[0];
            if (invoice != null)
            {
                txtInvoiceId.Text = invoice.InvoiceID;
                txtAmount.Text = invoice.TotalAmount.ToString();
                txtHospital.Text = invoice.HospitalName;
                string status = invoice.AuditStatus.ToString();
                if (status == "0")
                {
                    txtStatus.Text = "未提交";
                }
                else if (status == "1")
                {
                    txtStatus.Text = "已提交";
                }
            }
            else
            {
                PageError("给定发票不存在！", this.ReturnUrl);
            }

        }

    }
}
